<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<jsp:include page="/includes/top.jsp"></jsp:include>
<div class="page-header">
	<h1></h1>
</div>
<!-- /.page-header -->
<div class="row">
	<div class="col-xs-12">
		<ul class="nav nav-tabs" id="myTab">
			<li class="active"><a href="#tabs-0" data-toggle="tab" data-id="0">全部公司</a></li>
			<li><a href="#tabs-1" data-toggle="tab" data-id="1">客户</a></li>
			<li><a href="#tabs-2" data-toggle="tab" data-id="2">厂商</a></li>
			<li><a href="#tabs-3" data-toggle="tab" data-id="3">供应商</a></li>
			<li><a href="#tabs-4" data-toggle="tab" data-id="4">政府</a></li>
			<li><a href="#tabs-5" data-toggle="tab" data-id="5">公司内部</a></li>
			<li><a href="#tabs-6" data-toggle="tab" data-id="6">其他</a></li>
		</ul>
		<div class="tab-content">
			<div id="tabs-0" class="tab-pane fade in active">
				<div class="table-responsive">
					<table id="grid-table-0" class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th style="width:15px"><input type="checkbox"
									class="checkAll ace"><span class="lbl"></span></th>
								<th>公司名称</th>
								<th>活跃项目</th>
								<th>存档项目</th>
								<th>类型</th>

							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div id="tabs-1" class="tab-pane fade">
				<div class="table-responsive">
					<table id="grid-table-1" class="table table-striped table-bordered table-hover"
						style="width:100%">
						<thead>
							<tr>
								<th style="width:15px"><input type="checkbox"
									class="checkAll ace"><span class="lbl"></span></th>
								<th>公司名称</th>
								<th>活跃项目</th>
								<th>存档项目</th>
								<th>类型</th>

							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div id="tabs-2" class="tab-pane fade">
				<div class="table-responsive">
					<table id="grid-table-2" class="table table-striped table-bordered table-hover"
						style="width:100%">
						<thead>
							<tr>
								<th style="width:15px"><input type="checkbox"
									class="checkAll ace"><span class="lbl"></span></th>
								<th>公司名称</th>
								<th>活跃项目</th>
								<th>存档项目</th>
								<th>类型</th>

							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div id="tabs-3" class="tab-pane fade">
				<div class="table-responsive">
					<table id="grid-table-3" class="table table-striped table-bordered table-hover"
						style="width:100%">
						<thead>
							<tr>
								<th style="width:15px"><input type="checkbox"
									class="checkAll ace"><span class="lbl"></span></th>
								<th>公司名称</th>
								<th>活跃项目</th>
								<th>存档项目</th>
								<th>类型</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div id="tabs-4" class="tab-pane fade">
				<div class="table-responsive">
					<table id="grid-table-4" class="table table-striped table-bordered table-hover"
						style="width:100%">
						<thead>
							<tr>
								<th style="width:15px"><input type="checkbox"
									class="checkAll ace"><span class="lbl"></span></th>
								<th>公司名称</th>
								<th>活跃项目</th>
								<th>存档项目</th>
								<th>类型</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div id="tabs-5" class="tab-pane fade">
				<div class="table-responsive">
					<table id="grid-table-5" class="table table-striped table-bordered table-hover"
						style="width:100%">
						<thead>
							<tr>
								<th style="width:15px"><input type="checkbox"
									class="checkAll ace"><span class="lbl"></span></th>
								<th>公司名称</th>
								<th>活跃项目</th>
								<th>存档项目</th>
								<th>类型</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div id="tabs-6" class="tab-pane fade">
				<div class="table-responsive">
					<table id="grid-table-6" class="table table-striped table-bordered table-hover"
						style="width:100%">
						<thead>
							<tr>
								<th style="width:15px"><input type="checkbox"
									class="checkAll ace"><span class="lbl"></span></th>
								<th>公司名称</th>
								<th>活跃项目</th>
								<th>存档项目</th>
								<th>类型</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>

<jsp:include page="/includes/bottom.jsp"></jsp:include>

<Script type="text/javascript">
	var columns = [
        	{
			 	"data" : "companyId",
				"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
					$(nTd).html("<input type='checkbox' name='checkList' value='" + sData + "' class='ace'><span class='lbl'></span>");
				}
	        },
			{
             	"data": "companyId",
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html("<a href='Company/companyDetailed.jsp?m="+mid+"&id="+sData+"'>"+oData.companyName+"</a>");
              	}
            },
			{"data" : "activeProject"},
			{"data" : "archiveProject"}, 
			{"data" : "companytype.companyTypeName"}];
	
	
	$("document").ready(function(){
		$("#myTab a").click(function (e) { 
			setCookie("companytab",$(this).attr("data-id"));
        });
		var num = getCookie("companytab");
		$("#myTab li:eq("+num+") a").tab("show"); 
		//checkbox全选
	    $(".checkAll").on("click", function () {
	        var num = getCookie("companytab");
	        num = num == "" ? 0 : num;
	        if ($(this).prop("checked")) {
	            $("#tabs-"+num+" input[name='checkList']").prop("checked", true);
	        } else {
	            $("#tabs-"+num+" input[name='checkList']").prop("checked", false);
	        }
	    });
	    
	    var dataMap = null;
   		//所有
		$("[href^='#tabs-']").each(function(index){
			if(index == 0){
				dataMap = {typeid : ''};
			}else{
				dataMap = {typeid : index};
			}
			//参数说明：id,url,data,column,length			
			tableload("grid-table-" + index,"companyid",dataMap,columns,15);
		});
   	});
	function getSelected(){
		var str = '';
		var num = getCookie("companytab");
		num = num == "" ? 0 : num;
	    $("#tabs-"+num+" input[name='checkList']:checked").each(function () {
	        str += $(this).val();
	        str += ",";
	    });
	    str = str.substr(0, str.length - 1);
	    return str;
	}
	function _addFun() {
	 	window.open("Company/companyform.jsp?m="+mid,"_self");	   
	}
	function _editFun(){
		var str = getSelected();
	    if (str != '' && str.indexOf(",") < 0) {
	        window.open("Company/companyform.jsp?m="+mid+"&id="+str,"_self");
	    } else {
	        alert("请选择一条记录操作");
	    }
	}
   	function _delFun(){
	   	var str = getSelected();
		 if (str != '' && str.indexOf(",") < 0) {
			if (confirm("确定要删除数据吗？")) {
				$.ajax({
				type : "post",
				url : "delcompany",
				data : {'company.companyId':str},
				success : function(data) {
					showDelMessage(data);
					window.open("Company/companylist.jsp?m="+mid,"_self");
				}
			});
			}
		} else {
			alert("请选择一条记录操作");
		}
		
	}
</Script>
